package com.example.demo.controller;

import com.example.demo.model.Result;
import com.example.demo.model.domain.User;
import com.example.demo.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 注册功能
     * @param userAccount 用户名
     * @param password 用户密码
     * @param checkPassword 密码二次校验
     * @return 统一返回
     */
    @GetMapping("/userRegister")
    public Result<User> userRegister(String userAccount, String password, String checkPassword){
        Result<User> userResult = userService.userRegister(userAccount, password, checkPassword);
        return userResult;
    }


    @RequestMapping("/userLogin")
    public Result<User> userLogin(String userAccount, String password, HttpServletRequest request){
        Result<User> userResult = userService.doLogin(userAccount, password,request);
        return userResult;
    }
}
